//
//  LCAppPackgerCell.m
//  LCAppPackager
//
//  Created by 贺彦文 on 2021/3/24.
//

#import "LCAppPackagerCell.h"

@interface LCAppPackagerCell ()
@property (nonatomic, strong) UILabel *buildNameLabel;
@property (nonatomic, strong) UILabel *buildVersionLabel;
@property (nonatomic, strong) UILabel *buildCreatedTimeLabel;
@property (nonatomic, strong) UILabel *buildUpdateDescriptionLabel;
@property (nonatomic, strong) UILabel *buildFileSizeLabel;
@property (nonatomic, strong) UILabel *buildDownloadCountLabel;
@property (nonatomic,strong) UIView *bottomLineView;
@end

@implementation LCAppPackagerCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupSubview];
    }
    return self;
}


- (void)setEntity:(LCAppPackageEntity *)entity {
    _entity = entity;
    self.buildNameLabel.text = entity.buildName;
    self.buildVersionLabel.text = [NSString stringWithFormat:@"%@(%@)",entity.buildVersion,entity.buildBuildVersion];
    self.buildCreatedTimeLabel.text = entity.buildCreated;
    self.buildFileSizeLabel.text = [NSString stringWithFormat:@"%.1fMB",entity.buildFileSize / (1024.0 * 1024.0)];
    self.buildDownloadCountLabel.text = [NSString stringWithFormat:@"下载%d次",entity.buildDownloadCount];
    self.buildUpdateDescriptionLabel.text = entity.buildUpdateDescription;
}
- (void)setupSubview {
    [self.contentView addSubview:self.buildNameLabel];
    [self.buildNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(20);
        make.top.equalTo(self.contentView).offset(10);
    }];
    [self.contentView addSubview:self.buildVersionLabel];
    [self.buildVersionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.buildNameLabel);
        make.top.equalTo(self.buildNameLabel.mas_bottom).offset(5);
    }];
    [self.contentView addSubview:self.buildFileSizeLabel];
    [self.buildFileSizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.buildVersionLabel.mas_right).offset(15);
        make.centerY.equalTo(self.buildVersionLabel);
    }];
    [self.contentView addSubview:self.buildDownloadCountLabel];
    [self.buildDownloadCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.buildFileSizeLabel.mas_right).offset(15);
        make.centerY.equalTo(self.buildVersionLabel);
    }];
    [self.contentView addSubview:self.buildCreatedTimeLabel];
    [self.buildCreatedTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.buildDownloadCountLabel.mas_right).offset(15);
        make.centerY.equalTo(self.buildVersionLabel);
    }];
    
    [self.contentView addSubview:self.buildUpdateDescriptionLabel];
    [self.buildUpdateDescriptionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.buildNameLabel);
        make.top.equalTo(self.buildVersionLabel.mas_bottom).offset(5);
    }];
    [self.contentView addSubview:self.bottomLineView];
    [self.bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(self.contentView);
        make.height.equalTo(@(1.0/UIScreen.mainScreen.scale));
    }];
}
- (UIView *)bottomLineView {
    if (!_bottomLineView) {
        _bottomLineView = [[UIView alloc] init];
        _bottomLineView.backgroundColor = [LCApperance silverColor];
    }
    return _bottomLineView;
}
- (UILabel *)buildDownloadCountLabel {
    if (!_buildDownloadCountLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = [LCApperance lightGreenColor];
        label.textAlignment = NSTextAlignmentLeft;
        _buildDownloadCountLabel = label;
    }
    return _buildDownloadCountLabel;
}
- (UILabel *)buildUpdateDescriptionLabel{
    if (!_buildUpdateDescriptionLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = [LCApperance lightGreenColor];
        label.textAlignment = NSTextAlignmentLeft;
        label.numberOfLines = 0;
        _buildUpdateDescriptionLabel = label;
    }
    return _buildUpdateDescriptionLabel;
}
- (UILabel *)buildFileSizeLabel{
    if (!_buildFileSizeLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = [LCApperance lightGreenColor];
        label.textAlignment = NSTextAlignmentLeft;
        _buildFileSizeLabel = label;
    }
    return _buildFileSizeLabel;
}
- (UILabel *)buildCreatedTimeLabel{
    if (!_buildCreatedTimeLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = [LCApperance lightGreenColor];
        label.textAlignment = NSTextAlignmentLeft;
        _buildCreatedTimeLabel = label;
    }
    return _buildCreatedTimeLabel;
}
- (UILabel *)buildVersionLabel{
    if (!_buildVersionLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = [LCApperance lightGreenColor];
        label.textAlignment = NSTextAlignmentLeft;
        _buildVersionLabel = label;
    }
    return _buildVersionLabel;
}
- (UILabel *)buildNameLabel{
    if (!_buildNameLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.font = [UIFont boldSystemFontOfSize:18];
        label.textColor = [LCApperance youngGreenColor];
        label.textAlignment = NSTextAlignmentLeft;
        _buildNameLabel = label;
    }
    return _buildNameLabel;
}

@end
